﻿using Microsoft.Phone.Controls;
using System.Windows.Controls;

namespace BootyShaker
{
    public partial class SettingsPage : PhoneApplicationPage
    {
        public SettingsPage()
        {
            InitializeComponent();
            slider_ValueChanged(Frequency, null);
            slider_ValueChanged(DampingRatio, null);
            slider_ValueChanged(GravityRatio, null);
          
            slider_ValueChanged(DragStrength, null);
            //slider_ValueChanged(LinearDamping, null);

        }



        private void btnSave_click(object sender, System.EventArgs e)
        {
            //appSettings.. = textBoxUsername.Text;
            //settings.PasswordSetting = passwordBoxPassword.Password;
            NavigationService.GoBack();
        }

        private void btnCancel_click(object sender, System.EventArgs e)
        {
            NavigationService.GoBack();
        }

        private void btnDefaults_click(object sender, System.EventArgs e)
        {

            Frequency.Value = AppSettings.FrequencyDefault;
            DampingRatio.Value = AppSettings.DampingRatioDefault;
            GravityRatio.Value = AppSettings.GravityRatioDefault;
                       DragStrength.Value = AppSettings.DragStrengthDefault;
           // LinearDamping.Value = AppSettings.LinearDampingDefault;
        }

        private void slider_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<double> e)
        {
            Slider s = (Slider)sender;
            if (s.Tag != null)
            {
                TextBlock lbl = ((System.Windows.Controls.TextBlock)(this.FindName((string)s.Tag)));
                if (lbl != null)
                {
                    if (lbl.Tag == null) { lbl.Tag = lbl.Text; }
                    lbl.Text = string.Format("{0} ({1:0.#})", (string)lbl.Tag, s.Value);
                }
            }
        }

        private void ToggleSwitch_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            MergeOverlay.Content = "Overlay";
        }

        private void ToggleSwitch_Unchecked(object sender, System.Windows.RoutedEventArgs e)
        {
            MergeOverlay.Content = "Merge";
        }
    }
}